﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using System.Data.SqlClient;

namespace GUI
{
    public partial class TraCuu : UserControl
    {
        public TraCuu()
        {
            InitializeComponent();
         
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            SearchManeger();
        }
        private void SearchManeger()
        {
            String str = "%" + tbSearch.Text + "%";
            if (cmbLuachon2.SelectedItem == null)
            {
                MessageBox.Show("Bạn phải chọn Item muốn tìm");
            }
            else
            {
                if (cmbLuachon2.SelectedItem.ToString() == "Sách")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuSach(str);
                }
                else if (cmbLuachon2.SelectedItem.ToString() == "Đọc Giả")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuDocGia(str);
                }
                else if (cmbLuachon2.SelectedItem.ToString() == "Báo TC")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuBaoTC(str);
                }
                else if (cmbLuachon2.SelectedItem.ToString() == "Phiếu Mượn")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuPhieuMuon(str);
                }
                else if (cmbLuachon2.SelectedItem.ToString() == "Phiếu Trả")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuPhieuTra(str);
                }
                else if (cmbLuachon2.SelectedItem.ToString() == "Tác Giả")
                {
                    dgvSearch.DataSource = TraCuuDAO.TraCuuTacGia(str);
                }
            }
        }

        private void tbSearch_TextChanged(object sender, EventArgs e)
        {
            SearchManeger();
        }
    }
}
